package com.example.demo.controller;
import com.example.demo.model.*;
import com.example.demo.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
//管理员用户控制层
@Controller
@RequestMapping("/admin/adminUser")
public class AchieveController {
    @Resource
    private supplierService supp;
    @RequestMapping("/findsupplier")
    public String findsupplier(Model model)
    {
        supp.deleteAllBySnameIsNull();
        List<supplier> suppl = supp.findAll();
        model.addAttribute("find",suppl);
        return ("/adminUser/findsupplier");
    }
    @RequestMapping("/entersupplier")
    public String  entersupplier(HttpServletRequest request )//录入供应商
    {//获取增加供应商的信息
        supplier suppl = new supplier();
        suppl.setSno( request.getParameter("sno"));
        suppl.setSname(request.getParameter("sname"));
        suppl.setSphone(request.getParameter("sphone"));
        suppl.setSintroduction(request.getParameter("sintroduction"));
        suppl.setScontacts(request.getParameter("scontacts"));
        suppl.setScontactsphone(request.getParameter("scontactsphone"));
        suppl.setSlocation(request.getParameter("slocation"));
        suppl.setSemail(request.getParameter("semail"));
        suppl.setSremarks(request.getParameter("sremarks"));
        supp.save(suppl);

        return ("/adminUser/entersupplier");
    }
  @RequestMapping("/changesupplier")
    public String changesupplier(HttpServletRequest request)
  {
      String Sno = request.getParameter("sno");
      String Sname = request.getParameter("sname");
      String Sphone = request.getParameter("sphone");
      String Sintroduction = request.getParameter("sintroduction");
      String Scontacts = request.getParameter("scontacts");
      String Scontactsphone = request.getParameter("scontactsphone");
      String Slocation = request.getParameter("slocation");
      String Semail = request.getParameter("semail");
      String Sremarks = request.getParameter("sremarks");
      supplier suppl = new supplier(Sno,Sname,Sphone,Sintroduction,Scontacts,Scontactsphone,Slocation,Semail,Sremarks);
      supp.save(suppl);

      return ("adminUser/changesupplier");
  }
    @RequestMapping("/deletesupplier")
    public String deletesupplier(HttpServletRequest httpServletRequest)
    {
      String sno = httpServletRequest.getParameter("sno");
      supp.delete(sno);
        return ("adminUser/deletesupplier");
    }


    @Resource
    private goodsService good;
    @RequestMapping("/findgoods")
    public String findgoods(Model model)
    {
        good.deleteAllByGnameIsNull();
        List<goods>  goodsList= good.findAll();
        model.addAttribute("goo",goodsList);
        return ("/adminUser/findgoods");
    }
    @RequestMapping("/entergoods")
    public String  entergoods(HttpServletRequest request )//录入商品
    {//获取增加商品的信息
        goods suppl = new goods();
        suppl.setGno( request.getParameter("gno"));
        suppl.setgname(request.getParameter("gname"));
        suppl.setGprice(request.getParameter("gprice"));
        suppl.setSno(request.getParameter("sno"));
        suppl.setGintroduction(request.getParameter("introduction"));
        suppl.setGremarks(request.getParameter("remarks"));
        good.save(suppl);
        return ("/adminUser/entergoods");
    }

    @RequestMapping("/changegoods")
    public String changegoods(HttpServletRequest request)
    {
        goods suppl = new goods();
        suppl.setGno( request.getParameter("gno"));
        suppl.setgname(request.getParameter("gname"));
        suppl.setGprice(request.getParameter("gprice"));
        suppl.setSno(request.getParameter("sno"));
        suppl.setGintroduction(request.getParameter("introduction"));
        suppl.setGremarks(request.getParameter("remarks"));
        good.save(suppl);
        return ("adminUser/changegoods");
    }
    @RequestMapping("/deletegoods")
    public String deletegoods(HttpServletRequest httpServletRequest)
    {
        String gno = httpServletRequest.getParameter("gno");
        good.delete(gno);
        return ("adminUser/deletegoods");
    }



    @Resource
    private employeeService employee;
    @RequestMapping("/findemployee")
    public String findemployee(Model model)
    {
        employee.deleteAllByEnameIsNull();
        List<employee>  employeeList= employee.findAll();
        model.addAttribute("emp",employeeList);
        return ("/adminUser/findemployee");
    }
    @RequestMapping("/enteremployee")
    public String  enteremployee(HttpServletRequest request )
    {
        employee suppl = new employee();
        suppl.setEno(request.getParameter("eno"));
        suppl.setename(request.getParameter("ename"));
        suppl.setEsalary(request.getParameter("salary"));
        suppl.setEpassword(request.getParameter("password"));
        suppl.setElevel(request.getParameter("level"));
        suppl.setEphone(request.getParameter("phone"));
        suppl.setEremarks(request.getParameter("remarks"));
        employee.save(suppl);
        return ("/adminUser/enteremployee");
    }

    @RequestMapping("/changeemployee")
    public String changeemployee(HttpServletRequest request)
    {
        employee suppl = new employee();
        suppl.setEno(request.getParameter("eno"));
        suppl.setename(request.getParameter("ename"));
       suppl.setEsalary(request.getParameter("salary"));
        suppl.setEpassword(request.getParameter("password"));
        suppl.setElevel(request.getParameter("level"));
        suppl.setEphone(request.getParameter("phone"));
        suppl.setEremarks(request.getParameter("remarks"));
        employee.save(suppl);
        return ("adminUser/changeemployee");
    }
    @RequestMapping("/deleteemployee")
    public String deleteemployee(HttpServletRequest httpServletRequest)
    {
        String eno = httpServletRequest.getParameter("eno");
        employee.delete(eno);
        return ("adminUser/deleteemployee");
    }



    @Resource
    private purchaseDetailsService purchaseDetails;
    @RequestMapping("/findpurchaseDetails")
    public String findpurchaseDetails(Model model)
    {
        purchaseDetails.deleteAllByPdpriceIsNull();
        List<purchaseDetails> purchaseDetailsList= purchaseDetails.findAll();
        model.addAttribute("purchaseD",purchaseDetailsList);
        return ("/adminUser/findpurchaseDetails");
    }
    @RequestMapping("/enterpurchaseDetails")
    public String  enterpurchaseDetails(HttpServletRequest request )
    {
        purchaseDetails suppl = new purchaseDetails();
        suppl.setPDno(request.getParameter("pdno"));
        suppl.setPMno(request.getParameter("pmno"));
        suppl.setGno(request.getParameter("gno"));
        suppl.setpdprice(request.getParameter("price"));
        suppl.setPDsumprice(request.getParameter("sumprice"));
        suppl.setPDcount(request.getParameter("count"));
        suppl.setPDremarks(request.getParameter("remarks"));
        purchaseDetails.save(suppl);
        return ("/adminUser/enterpurchaseDetails");
    }

    @RequestMapping("/changepurchaseDetails")
    public String changepurchaseDetails(HttpServletRequest request)
    {
        purchaseDetails suppl = new purchaseDetails();
        suppl.setPDno(request.getParameter("pdno"));
        suppl.setPMno(request.getParameter("pmno"));
        suppl.setGno(request.getParameter("gno"));
        suppl.setpdprice(request.getParameter("price"));
        suppl.setPDsumprice(request.getParameter("sumprice"));
        suppl.setPDcount(request.getParameter("count"));
        suppl.setPDremarks(request.getParameter("remarks"));
        purchaseDetails.save(suppl);
        return ("adminUser/changepurchaseDetails");
    }
    @RequestMapping("/deletepurchaseDetails")
    public String deletepurchaseDetails(HttpServletRequest httpServletRequest)
    {
        String pdn = httpServletRequest.getParameter("pdno");
        purchaseDetails.delete(pdn);
        return ("adminUser/deletepurchaseDetails");
    }

    @Resource
    private purchaseMainService purchaseMain;
    @RequestMapping("/findpurchaseMain")
    public String findpurchaseMain(Model model)
    {
        purchaseMain.deleteAllByPmpriceIsNull();
        List<purchaseMain> purchaseMainList= purchaseMain.findAll();
        model.addAttribute("purchaseM",purchaseMainList);
        return ("/adminUser/findpurchaseMain");
    }
    @RequestMapping("/enterpurchaseMain")
    public String  enterpurchaseMain(HttpServletRequest request )
    {
        purchaseMain suppl = new purchaseMain();
        suppl.setPMno(request.getParameter("pmno"));
        suppl.setEno(request.getParameter("eno"));
        suppl.setPMtime(request.getParameter("time"));
        suppl.setpmprice(request.getParameter("price"));
        suppl.setPMcount(request.getParameter("count"));
        suppl.setPMremarks(request.getParameter("remarks"));
        purchaseMain.save(suppl);
        return ("/adminUser/enterpurchaseMain");
    }

    @RequestMapping("/changepurchaseMain")
    public String changepurchaseMain(HttpServletRequest request)
    {
        purchaseMain suppl = new purchaseMain();
        suppl.setPMno(request.getParameter("pmno"));
        suppl.setEno(request.getParameter("eno"));
        suppl.setPMtime(request.getParameter("time"));
        suppl.setpmprice(request.getParameter("price"));
        suppl.setPMcount(request.getParameter("count"));
        suppl.setPMremarks(request.getParameter("remarks"));
        purchaseMain.save(suppl);
        return ("adminUser/changepurchaseMain");
    }
    @RequestMapping("/deletepurchaseMain")
    public String deletepurchaseMain(HttpServletRequest httpServletRequest)
    {
        String pmn = httpServletRequest.getParameter("pmno");
        purchaseMain.delete(pmn);
        return ("adminUser/deletepurchaseMain");
    }





}
